var net = require("net");
var charServer = net.createServer();

chatList=[];
charServer.on('connection' , function(client){
            client.name = client.remoteAddress + ":" + client.remotePort;
            client.write("Hi!\n");
            console.log(client.name +  " joined!");
            chatList.push(client);

            client.on('data' , function(data){
                    for(var i = 0 ; i < chatList.length ; i++){
                        if(client != chatList[i]){
                            chatList[i].write(data);
                        }
                    }
                });

            client.on("end" , function(){
                    clientList.splice(chatList.indexOf(client) , 1);
                });
            client.on("error", function(e){
                console.log(e);
            });
        });

charServer.listen(9000);
console.log("server is started @9000");
